package com.mj.mafeed.dao;

import java.util.ArrayList;
import java.util.List;

import com.mj.mafeed.bean.PaymentMethodJSON;
import com.mj.mafeed.util.DBHelper;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

/**
 * 支付方式
 * @author zhaominglei
 * @date 2014-12-23
 * 
 */
public class PaymentMethodDao extends BaseDao {
	private static final String TABLE_NAME = "feed_payment_method";
	
	public int getCount(Context context) {
		return getCount(context, TABLE_NAME);
	}
	
	public void deleteAll(Context context) {
		deleteAll(context, TABLE_NAME);
	}
	
	public List<PaymentMethodJSON> getAll(Context context) {
		List<PaymentMethodJSON> recordList = new ArrayList<PaymentMethodJSON>();
		SQLiteDatabase db = DBHelper.getInstance(context).getReadableDatabase();
		Cursor cursor = db.query(TABLE_NAME, null, null, null, null, null, null);
		while(cursor.moveToNext()) {
			PaymentMethodJSON paymentMethodJSON = new PaymentMethodJSON();
			paymentMethodJSON.setPaymentMethodId(cursor.getLong(cursor.getColumnIndex("paymentmethodid")));
			paymentMethodJSON.setOrders(cursor.getInt(cursor.getColumnIndex("orders")));
			paymentMethodJSON.setName(cursor.getString(cursor.getColumnIndex("name")));
			paymentMethodJSON.setMethod(cursor.getInt(cursor.getColumnIndex("method")));
			paymentMethodJSON.setTimeout(cursor.getInt(cursor.getColumnIndex("timeout")));
			paymentMethodJSON.setIcon(cursor.getString(cursor.getColumnIndex("icon")));
			paymentMethodJSON.setDescription(cursor.getString(cursor.getColumnIndex("description")));
			paymentMethodJSON.setContent(cursor.getString(cursor.getColumnIndex("content")));
			recordList.add(paymentMethodJSON);
		}
		cursor.close();
		return recordList;
	}
}
